Skip to content

ADD: Unit tests for plot_confusion_matrix with mock CSV data - #15

Merged
rcjackson merged 4 commits into
ARM-Development:mainfrom
rcjackson:ghactions
Apr 23, 2026
Merged

rcjackson merged 4 commits into
ARM-Development:mainfrom
rcjackson:ghactions

Conversation

@rcjackson

Copy link
Copy Markdown
Collaborator

Adds unit tests for the plot_confusion_matrix function.

Robert Jackson and others added 4 commits April 23, 2026 12:07
Adds tests/test_confusion_matrix.py with five tests covering title,
return value, normalization, custom column names, and default-axis
behavior. Removes sklearn from conftest mocks (real sklearn is now
installed in CI) and adds scikit-learn to the workflow pip install.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds test_confusion_matrix_counts (raw integer counts) and
test_normalized_confusion_matrix_values (row-normalized floats).
Both extract the plotted image array from ax.images[0] and compare
against the expected 3x3 matrix derived from the CSV fixture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
On headless runners (GitHub Actions Ubuntu), importing matplotlib.pyplot
before setting the backend can raise if no GUI toolkit (Tk, Qt) is
installed, aborting conftest.py before the sys.modules mocks are applied.
Without those mocks lars cannot be imported, causing the patch() call in
mock_openai to fail with ModuleNotFoundError.

Fix: move the sys.modules mock loop to the top of conftest.py, then call
matplotlib.use("Agg") before pyplot is imported anywhere. Also set
MPLBACKEND=Agg in the workflow as a belt-and-suspenders guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
scipy's is_torch_array() checks sys.modules['torch'] and calls
issubclass(cls, mod.Tensor). With torch mocked as MagicMock, Tensor
is a MagicMock instance rather than a class, raising TypeError.

lars never imports torch or torchvision, so there is nothing to stub.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rcjackson
rcjackson merged commit 9682ca1 into ARM-Development:main Apr 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant